"""
数值策划
E(期望收益) = ∑(n, i=1)Vi * P(Vi)
E(净收益) = T(成本) - E(期望收益)
"""


class NumericPlan:
    def __init__(self, value_arr: [float], count_arr: [int]):
        if len(value_arr) != len(count_arr):
            raise ValueError("Two arrays are not same size！")
        self.value_arr = value_arr
        self.count_arr = count_arr

    def predict(self, cost: float) -> int:
        # 计算总数
        total = sum(self.count_arr)
        # 计算期望收益
        e = 0.0
        for i in range(0, len(self.count_arr)):
            count_i = self.count_arr[i]
            value_i = self.value_arr[i]
            rate = (count_i / total)
            current_v = rate * value_i
            e += current_v

        # 计算净值
        r = cost - e
        # 成本 < 收益：亏
        if r > 0.0:
            return -1
        # 成本 = 收益：不赚不亏
        elif r == 0:
            return 0
        # 成本 > 收益：赚
        else:
            return 1


"""
红包中有1张100块和10张1块，随机抽1张，10块抽一次划算嘛？
"""
instance = NumericPlan([100, 1], [1, 10])
pr = instance.predict(10)
print(f"Final Predict Value = {pr}")